<?php
/**
 * Created by PhpStorm.
 * User: zhangrongxiang
 * Date: 2018/2/14
 * Time: 下午9:15
 */

$arr    = [ 1, 2, 3, ];
$result = array_rand( $arr );
echo $arr[ $result ] . PHP_EOL;
print_r( $arr );
$result = array_rand( $arr, 2 );
print_r( $result );
echo $arr[ $result[0] ] . PHP_EOL;
echo $arr[ $result[1] ] . PHP_EOL;

$arr    = [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ];
$result = array_rand( $arr );
print_r( $arr[ $result ] );

$arr = array( "apple", "banana", "cherry" );
echo array_rand( array_flip( $arr ) ) . PHP_EOL;